<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html>
<head>
    <title>退货管理  退货记录明细 （配送企业端）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>

<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
        <h1>退货单明细</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="${ctx}/returnConfirm/toReturnOrderHis.html">退货管理  </a></li>
            <li class="active"><a href="#">退货单查看</a></li>
            <li class="active"><a href="#">退货单</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                
                    
                
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">批次号：</label>
                        <input class="form-control" type="text" id="lotId" name="lotId" placeholder="批次号" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">药品编码：</label>
                        <input class="form-control" type="text" id="drugCode" name="drugCode" placeholder="药品编码" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">通用名：</label>
                        <input class="form-control" type="text" id="drugName" name="drugName" placeholder="通用名" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">生产企业：</label>
                        <input class="form-control" type="text" id="compName" name="compName" placeholder="生产企业" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchrecpAddr">医疗机构：</label>
                        <input class="form-control" type="text" id="hospName" name="hospName" placeholder="医疗机构" />
                    </div>
                    
                     <div class="form-group form-group-xs">
                        <label for="searchrecpAddr"> 退货日期：</label>
                        <input class="form-control" type="text" id="startDate" name="startDate"
                            onFocus="var endDate=$dp.$('endDate');WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}'})" />
                        -
                        <input class="form-control" type="text" id="endDate"  name="endDate"
                            onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}'})" />
                    </div>
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查  询</button>
                    
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <a href="${ctx}/returnConfirm/toReturnOrderHis.html" class="btn btn-default btn-sm">返  回</a>
        </div>
        
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
        function showFocus(rowId) {
            $("#gridlist").resetSelection();
            $("#gridlist").setSelection(rowId);
        }
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getReturnOrderHisDetail.html",
                mtype: "POST",
                postData:{"retCode":"${retCode}"},
                datatype: "json",
                autowidth: true,
                shrinkToFit: false,
                height: 270,
                colNames: ['退货明细编号',
                           '批次号',
                           '医疗机构',
                           '采购价',
                           '退货数量',
                           '退货原因',
                           '药品编码',
                           '通用名',
                           '剂型',
                           '规格',
                           '转换系数',
                           '单位',
                           '材质',
                           '生产企业',
                           '退货时间',
                           '退货人',
                           '状态',
                           '确认时间',
                           '确认人',
                           '确认备注'
                           ],
                colModel: [
                       { name: 'retDetailCode', index: 'sdate', width: 210, align: "center",sortable:false},
                       { name: 'lotId', index: 'sdate', width: 70, align: "center",sortable:false},
                       { name: 'hospName', index: 'ship', width: 160,align:"left",sortable:false,
                           formatter:function(cellvalue, options, row){
                               return '<a href="javascript:showHospInfo(\''+ row.hospId +'\');">'+cellvalue+'</a>';
                           }
                       },
                       { name: 'proPrice', index: 'sdate', width: 60, align: "right",sortable:false,
                     	   formatter:function(cellvalue, options, row){
                               return formatAmount(cellvalue, options, row);
                           }},
                       { name: 'retCount', index: 'sdate', width: 70, align: "center",sortable:false},
                       { name: 'retReason', index: 'sdate', width: 80, align: "center",sortable:false},
                       { name: 'drugCode', index: 'ship', width: 100, align: "center",sortable:false,
                           formatter:function(cellvalue, options, row){
                               return '<a href="javascript:showDrugInfo(\''+ row.drugId +'\');">'+cellvalue+'</a>';
                           }
                       },
                       { name: 'drugName', index: 'name', width: 120, align: "left" ,sortable:false },
                       { name: 'formName', index: 'stock', width: 80 , align: "center",sortable:false},
                       { name: 'specName', index: 'ship', width: 80, align: "left" ,sortable:false},
                       { name: 'factor', index: 'ship', width: 80, align: "center" ,sortable:false},
                       { name: 'unit', index: 'ship', width: 40, align: "center" ,sortable:false},
                       { name: 'materialName', index: 'ship', width: 80, align: "center" ,sortable:false},
                       { name: 'compName', index: 'ship', width: 180, align: "left",sortable:false,
                           formatter:function(cellvalue, options, row){
                               return '<a href="javascript:showCompInfo(\''+ row.compId +'\');">'+cellvalue+'</a>';
                           }
                       },
                       { name: 'submitTime', index: 'sdate', width: 140, align: "center",sortable:false},
                       { name: 'submitUserName', index: 'sdate', width: 180, align: "center",sortable:false},
                       { name: 'status', index: 'sdate', width: 60, align: "center",sortable:false},
                       { name: 'confirmTime', index: 'sdate', width: 140, align: "center",sortable:false},
                       { name: 'confirmUserName', index: 'sdate', width: 120, align: "center",sortable:false},
                       { name: 'confirmRemark', index: 'sdate', width: 180, align: "center",sortable:false}
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                multiselect: false,
                pager: "#gridpage",
                viewrecords: true,
                caption: "退货单号${param.retCode} ",
                jsonReader: {
                    repeatitems: false,
                    id: "retDetailId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        /* 日期查询 */
        var date = new Date();
        date.setMonth(date.getMonth() - 1);
        $('#startDate').val(date.format("yyyy-MM-dd"));
        $('#endDate').val(new Date().format("yyyy-MM-dd"));
        
        
        
        /* 查询 */
        function search(page) {
            var retDetailCode = $.trim($("#retDetailCode").val());
            var lotId = $.trim($("#lotId").val());
            var drugCode = $.trim($("#drugCode").val());
            var drugName = $.trim($("#drugName").val());
            var compName = $.trim($("#compName").val());
            var hospName = $.trim($("#hospName").val());
            var startDate = $.trim($("#startDate").val());
            var endDate = $.trim($("#endDate").val());
            $("#gridlist").jqGrid("clearGridData");
                $("#gridlist").jqGrid('setGridParam',{  
                mtype: "POST",
                datatype:'json',
                postData:{
					"retCode":"${retCode}",
					"retDetailCode":retDetailCode, 
                          "lotId":lotId,
                          "drugCode":drugCode, 
                          "drugName":drugName,
                          "compName":compName, 
                          "hospName":hospName,
                          "startDate":startDate,
                          "endDate":endDate
                },
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
        
        /* 同意 */
        function agreeReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "消息", "warn");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"retDetailId":rowId, "status":status});
            }
            $.post("agreeReturnConfirm.html", {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                    search(curpage);
                    $.HN.message.alert("操作成功！", "消息", "success");
                } else {
                    $.HN.message.alert("操作失败！", "消息", "error");
                }
            }, "json")
        }
        
        
        /* 拒绝 */
        function rejectReturnConfirm(status) {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "消息", "warn");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"retDetailId":rowId, "status":status});
            }
            $.post("rejectReturnConfirm.html", {
                "array" : json.jsonToString(list)
            }, function(result) {
                if (result.success) {
                    var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                    search(curpage);
                    $.HN.message.alert("操作成功！", "消息", "success");
                } else {
                    $.HN.message.alert("操作失败！", "消息", "error");
                }
            }, "json")
        }
        
        
        
        //医疗机构信息弹窗
        function showHospInfo(hospId) {
            $.HN.dialog.open({
                "id": "showHospInfo", 
                "title": "医疗机构信息", 
                "url": "${ctx}/stdHospInfo/hospInfoDetail.html?hospId="+hospId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }
        
        //药品信息弹窗
        function showDrugInfo(drugId) {
            $.HN.dialog.open({
                "id": "showDrugInfo", 
                "title": "药品信息", 
                "url": "${ctx}/stdDrug/drugInfoDetail.html?drugId="+drugId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }
        
        //生产企业信息弹窗
        function showCompInfo(prodCompId) {
            $.HN.dialog.open({
                "id": "showCompInfo", 
                "title": "生产企业信息", 
                "url": "${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+prodCompId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }

        
    </script>
</body>
</html>